package com.eastfair.venueservice.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONObject;
//import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.eastfair.boot.request.PageParams;
import com.eastfair.boot.service.SuperServiceImpl;
import com.eastfair.constant.BusinessConstant;
import com.eastfair.core.base.R;
import com.eastfair.core.base.entity.SuperEntity;
import com.eastfair.core.context.ContextUtil;
import com.eastfair.core.exception.BizException;
import com.eastfair.core.utils.ConvertUtil;
import com.eastfair.database.mybatis.typehandler.TypeHandlerUtil;
import com.eastfair.venueservice.dao.EvaluateComplaintMapper;
import com.eastfair.venueservice.dto.EvaluateComplaintDTO;
import com.eastfair.venueservice.entity.EvaluateComplaint;
import com.eastfair.venueservice.entity.ServiceItem;
import com.eastfair.venueservice.entity.ServicePriceListItem;
import com.eastfair.venueservice.entity.ViolationRecord;
import com.eastfair.venueservice.enums.EvaluateComplaintLevelEnum;
import com.eastfair.venueservice.service.EvaluateComplaintService;
import com.eastfair.venueservice.service.ServicePriceListItemService;
import com.eastfair.venueservice.service.ServiceProviderService;
import com.eastfair.venueservice.service.ViolationRecordService;
import com.eastfair.venueservice.vo.EvaluateComplaintVO;
import com.google.common.collect.Maps;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.compress.utils.Lists;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.*;
import java.util.stream.Collectors;

/**
 * <p>
 * 业务实现类
 * 评价投诉记录
 * </p>
 *
 * @author lyw
 * @date 2023-02-03
 */
@Slf4j
@Service
//@DS("#thread.tenant")
public class EvaluateComplaintServiceImpl extends SuperServiceImpl<EvaluateComplaintMapper, EvaluateComplaint> implements EvaluateComplaintService {


    @Resource
    private ViolationRecordService violationRecordService;

    @Resource
    private ServiceProviderService serviceProviderService;

    @Resource
    private ServicePriceListItemService servicePriceListItemService;

    @Resource
    private ServiceItemServiceImpl serviceItemService;

    @Resource
    private EvaluateComplaintMapper evaluateComplaintMapper;

    @Override
    protected R<Boolean> handlerSave(EvaluateComplaint model) {
        model.setProjectId(ContextUtil.getProjectId());
        model.setSubsystemId(ContextUtil.getSubSystemId());
        return R.successDef();
    }

    /**
     * 处理逻辑删除相关处理
     *
     * @param modelList 实体
     * @return 是否成功
     */
    @Override
    protected R<Boolean> handlerRemoveByIdsOfLogic(Collection<EvaluateComplaint> modelList) {
        modelList.forEach(s -> s.setIsDeleted(BusinessConstant.YES));
        return R.successDef();
    }

    private static QueryWrapper<EvaluateComplaint> createEvaluateComplaintVOQueryWrapper(EvaluateComplaintDTO evaluateComplaintDTO) {
        QueryWrapper<EvaluateComplaint> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda()
                .eq(EvaluateComplaint::getIsDeleted, BusinessConstant.DELETE_NO)
                .eq(Objects.nonNull(evaluateComplaintDTO.getEvaluateType()), EvaluateComplaint::getEvaluateType, evaluateComplaintDTO.getEvaluateType())
                .like(StrUtil.isNotBlank(evaluateComplaintDTO.getServiceName()), EvaluateComplaint::getServiceName, evaluateComplaintDTO.getServiceName())
                .like(StrUtil.isNotBlank(evaluateComplaintDTO.getUserName()), EvaluateComplaint::getUserName, evaluateComplaintDTO.getUserName())
                .like(StrUtil.isNotBlank(evaluateComplaintDTO.getMobile()), EvaluateComplaint::getMobile, TypeHandlerUtil.crypt(evaluateComplaintDTO.getMobile()))
                .eq(Objects.nonNull(evaluateComplaintDTO.getExhibitionManageId()), EvaluateComplaint::getExhibitionManageId, evaluateComplaintDTO.getExhibitionManageId())
                .eq(Objects.nonNull(evaluateComplaintDTO.getServiceProviderId()), EvaluateComplaint::getServiceProviderId, evaluateComplaintDTO.getServiceProviderId())
                .eq(Objects.nonNull(evaluateComplaintDTO.getEvaluateServiceProviderId()), EvaluateComplaint::getEvaluateServiceProviderId, evaluateComplaintDTO.getEvaluateServiceProviderId())
                .eq(Objects.nonNull(evaluateComplaintDTO.getUserNumber()), EvaluateComplaint::getUserNumber, evaluateComplaintDTO.getUserNumber())
                .in(evaluateComplaintDTO.getServiceIdList() != null && !evaluateComplaintDTO.getServiceIdList().isEmpty(), EvaluateComplaint::getServiceId, evaluateComplaintDTO.getServiceIdList())
                .orderByDesc(EvaluateComplaint::getCreateTime);
        return queryWrapper;
    }

    public void handlerQueryParams(PageParams<EvaluateComplaintDTO> pageParams) {
        if (StrUtil.isBlank(pageParams.getSort()) || StrUtil.isBlank(pageParams.getOrder())) {
            pageParams.setSort("createTime");
            pageParams.setOrder("descending");
        }
    }

    @Override
    public IPage<EvaluateComplaintVO> queryEvaluateComplaintList(PageParams<EvaluateComplaintDTO> pageParams) {
        log.info("EvaluateComplaintServiceImpl +++++ queryEvaluateComplaintList - 分页查询评价投诉列表 pageParams={}", JSONObject.toJSON(pageParams));
        handlerQueryParams(pageParams);
        Page<EvaluateComplaint> page = pageParams.buildPage();
        EvaluateComplaintDTO evaluateComplaintPageQuery = pageParams.getModel();
        QueryWrapper<EvaluateComplaint> queryWrapper = createEvaluateComplaintVOQueryWrapper(evaluateComplaintPageQuery);
        page = page(page, queryWrapper);
        return ConvertUtil.convertPage(page, EvaluateComplaintVO.class);
    }

    @Override
    public IPage<EvaluateComplaintVO> queryForVenueExhibition(PageParams<EvaluateComplaintDTO> pageParams) {
        log.info("queryForVenueExhibition - 场馆综合展会详情查询评价投诉列表, pageParams={}", pageParams);
        EvaluateComplaintDTO model = pageParams.getModel();
        Long exhibitionManageId = model.getExhibitionManageId();
        if (exhibitionManageId != null) {
            // 查询展会价目表的服务项列表
            List<ServicePriceListItem> serviceList = servicePriceListItemService.listByExhibitionManageId(exhibitionManageId);
            if (serviceList == null || serviceList.isEmpty()) {
                return new Page<>();
            }
            List<Long> serviceIdList = serviceList
                    .stream()
                    .map(ServicePriceListItem::getServiceItemId)
                    .collect(Collectors.toList());
            // 查询服务系统同步之后的服务列表
            List<ServiceItem> serviceProviderServiceList = serviceItemService.listBySourceIdList(serviceIdList);
            if (serviceProviderServiceList != null && !serviceProviderServiceList.isEmpty()) {
                List<Long> serviceProviderServiceIdList = serviceProviderServiceList
                        .stream()
                        .map(SuperEntity::getId)
                        .collect(Collectors.toList());
                serviceIdList.addAll(serviceProviderServiceIdList);
            }
            model.setServiceIdList(serviceIdList);
        }
        return queryEvaluateComplaintList(pageParams);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean saveEvaluateComplaintInfo(EvaluateComplaintDTO evaluateComplaintDTO) {
        log.info("EvaluateComplaintServiceImpl +++++ saveEvaluateComplaintInfo - 保存评价投诉 evaluateComplaintDTO={}", JSONObject.toJSON(evaluateComplaintDTO));
        EvaluateComplaint evaluateComplaint = BeanUtil.toBean(evaluateComplaintDTO, EvaluateComplaint.class);
        evaluateComplaint.setEvaluateTime(LocalDateTime.now());
        // 判断保存的信息是否为null
        if (Objects.isNull(evaluateComplaint.getEvaluateType())) {
            throw BizException.wrap(-1, "保存评价投诉类型不能为空");
        }
        save(evaluateComplaint);
        // 给被评价企业扣分
        if(evaluateComplaint.getEvaluateServiceProviderId() == null) {
            return true;
        }
        // 评价类型为投诉，则信用分值扣5分
        if (evaluateComplaint.getEvaluateType() == BusinessConstant.NO) {
            serviceProviderService.updateCreditScore(evaluateComplaint.getEvaluateServiceProviderId(), -5);
        }
        // 评价类型为评价，则计算对应的信用分值并扣除
        if (evaluateComplaint.getEvaluateType() == BusinessConstant.YES) {
            for (EvaluateComplaintLevelEnum evaluateComplaintLevelEnum: EvaluateComplaintLevelEnum.values()) {
                if (evaluateComplaintLevelEnum.getLevel().equals(evaluateComplaint.getScore())) {
                    serviceProviderService.updateCreditScore(evaluateComplaint.getEvaluateServiceProviderId(), evaluateComplaintLevelEnum.getScore());
                }
            }
        }
        return true;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean updateEvaluateComplaintById(EvaluateComplaintDTO evaluateComplaintDTO) {
        log.info("EvaluateComplaintServiceImpl +++++ updateEvaluateComplaintById - 修改评价投诉 evaluateComplaintDTO={}", JSONObject.toJSON(evaluateComplaintDTO));
        // 修改评价投诉
        EvaluateComplaint evaluateComplaint = BeanUtil.toBean(evaluateComplaintDTO, EvaluateComplaint.class);
        updateById(evaluateComplaint);
        if (StrUtil.isNotBlank(evaluateComplaintDTO.getReplyContent())) {
            updateEvaluateComplaintReply(evaluateComplaintDTO);
        }
        return true;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean updateEvaluateComplaintReply(EvaluateComplaintDTO evaluateComplaintDTO) {
        log.info("updateEvaluateComplaintReply - 更新评价回复, evaluateComplaintDTO={}", evaluateComplaintDTO);
        EvaluateComplaint evaluateComplaint = getById(evaluateComplaintDTO.getId());
        if (evaluateComplaint == null) {
            throw BizException.wrap(-1, "评价投诉记录不存在");
        }
        evaluateComplaint.setIsReply(BusinessConstant.YES);
        evaluateComplaint.setReplyContent(evaluateComplaintDTO.getReplyContent());
        return updateById(evaluateComplaint);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean delEvaluateComplaintById(EvaluateComplaintDTO evaluateComplaintDTO) {
        log.info("EvaluateComplaintServiceImpl +++++ updateEvaluateComplaintById - 删除评价投诉 evaluateComplaintDTO={}", JSONObject.toJSON(evaluateComplaintDTO));
        EvaluateComplaint evaluateComplaint = BeanUtil.toBean(evaluateComplaintDTO, EvaluateComplaint.class);
        evaluateComplaint.setIsDeleted(BusinessConstant.DELETE_YES);
        return updateById(evaluateComplaint);
    }

    @Override
    public EvaluateComplaintVO getEvaluateComplaintInfoById(Long id) {
        log.info("EvaluateComplaintServiceImpl +++++ getEvaluateComplaintInfoById - id查询评价投诉详情 evaluateComplaintDTO={}", id);
        EvaluateComplaint evaluateComplaint = this.getById(id);
        if (evaluateComplaint == null) {
            return null;
        }
        return BeanUtil.toBean(evaluateComplaint, EvaluateComplaintVO.class);
    }

    /**
     * id查询服务商信誉等级
     *
     * @param id
     * @return
     */
    @Override
    public Map<String, List<String>> getReputationLevelById(Long id) {
        log.info("EvaluateComplaintServiceImpl +++++ getReputationLevelById - id查询服务商信誉等级 id={}", id);
        Map<String, List<String>> map = Maps.newHashMap();
        try {
            //获取评价投诉的数据
            Map<String, LocalDateTime> startAndEndTimeOne = getStartAndEndTime("1");
            List<String> list = getEvaluateComplaintList(startAndEndTimeOne, id);
            map.put("week", list);
            Map<String, LocalDateTime> startAndEndTimeTwo = getStartAndEndTime("2");
            List<String> list1 = getEvaluateComplaintList(startAndEndTimeTwo, id);
            map.put("month", list1);
            Map<String, LocalDateTime> startAndEndTimeThree = getStartAndEndTime("3");
            List<String> list2 = getEvaluateComplaintList(startAndEndTimeThree, id);
            map.put("halfYear", list2);
            Map<String, LocalDateTime> startAndEndTimeFour = getStartAndEndTime("4");
            List<String> list3 = getEvaluateComplaintList(startAndEndTimeFour, id);
            map.put("year", list3);
            Map<String, LocalDateTime> startAndEndTimeCount = Maps.newHashMap();
            List<String> list4 = getEvaluateComplaintList(startAndEndTimeCount, id);
            map.put("count", list4);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return map;
    }

    @Override
    public List<Map<String, Object>> countEvaluateServiceByExhibitionId(Long exhibitionManageId) {
        log.info("countEvaluateServiceByExhibitionId - 展会id的统计评价数量和未评价数量, exhibitionManageId={}", exhibitionManageId);
        Long hasEvaluateCount = countHasEvaluateServiceByExhibitionId(exhibitionManageId);
        Long notEvaluateCount = countNotEvaluateServiceByExhibitionId(exhibitionManageId);
        List<Map<String, Object>> list = new ArrayList<>();
        Map<String, Object> hasEvaluate = new HashMap<>(16);
        hasEvaluate.put("name", "已评价");
        hasEvaluate.put("value", hasEvaluateCount);
        list.add(hasEvaluate);
        Map<String, Object> notEvaluate = new HashMap<>(16);
        notEvaluate.put("name", "未评价");
        notEvaluate.put("value", notEvaluateCount);
        list.add(notEvaluate);
        return list;
    }

    @Override
    public Long countHasEvaluateServiceByExhibitionId(Long exhibitionManageId) {
        log.info("countHasEvaluateServiceByExhibitionId - 展会id的统计已评价服务数量, exhibitionManageId={}", exhibitionManageId);
        QueryWrapper<EvaluateComplaint> queryWrapper = new QueryWrapper<>();
        queryWrapper
                .eq("em.is_deleted", BusinessConstant.DELETE_NO)
                .eq(exhibitionManageId != null, "ec.exhibition_manage_id", exhibitionManageId)
                .isNotNull("ec.id")
        ;
        return evaluateComplaintMapper.countEvaluateServiceItemByExhibitionId(queryWrapper);
    }

    @Override
    public Long countNotEvaluateServiceByExhibitionId(Long exhibitionManageId) {
        log.info("countNotEvaluateServiceByExhibitionId - 展会id的统计未评价服务数量, exhibitionManageId={}", exhibitionManageId);
        QueryWrapper<EvaluateComplaint> queryWrapper = new QueryWrapper<>();
        queryWrapper
                .eq("em.is_deleted", BusinessConstant.DELETE_NO)
                .eq(exhibitionManageId != null, "ec.exhibition_manage_id", exhibitionManageId)
                .isNull("ec.id")
        ;
        return evaluateComplaintMapper.countEvaluateServiceItemByExhibitionId(queryWrapper);
    }

    @Override
    public List<Map<String, Object>> countScoreByExhibitionId(Long exhibitionManageId) {
        log.info("countScoreByExhibitionId - 展会id统计评星数量, exhibitionManageId={}", exhibitionManageId);
        QueryWrapper<EvaluateComplaint> queryWrapper = new QueryWrapper<>();
        queryWrapper
                .eq("em.is_deleted", BusinessConstant.DELETE_NO)
                .eq(exhibitionManageId != null, "ec.exhibition_manage_id", exhibitionManageId)
                .isNotNull("ec.score")
                .groupBy("ec.score")
        ;
        return evaluateComplaintMapper.countEvaluateScoreByExhibitionId(queryWrapper);
    }

    @Override
    public Map<String, Object> countServiceScoreByExhibitionId(Long exhibitionManageId, Integer topN) {
        log.info("countServiceScoreByExhibitionId - 展会ID统计各个服务的星级, exhibitionManageId={}, topN={}", exhibitionManageId, topN);
        // 查询评价数量topN服务
        List<EvaluateComplaintVO> serviceList = listEvaluateServiceByExhibitionId(exhibitionManageId, topN);
        // 查询服务的评星数量
        List<EvaluateComplaintVO> serviceScoreList = countServiceScoreByExhibitionId(exhibitionManageId);
        Map<Long, Map<Integer, Long>> serviceScoreMap = new HashMap<>(16);
        for (EvaluateComplaintVO serviceScore : serviceScoreList) {
            Map<Integer, Long> scoreMap = serviceScoreMap.computeIfAbsent(serviceScore.getServiceId(), key -> new HashMap<>(16));
            scoreMap.put(serviceScore.getScore(), serviceScore.getEvaluateCount());
        }
        List<String> serviceNameList = new ArrayList<>(16);
        List<Long> zeroScoreList = new ArrayList<>();
        List<Long> oneScoreList = new ArrayList<>();
        List<Long> twoScoreList = new ArrayList<>();
        List<Long> threeScoreList = new ArrayList<>();
        List<Long> fourScoreList = new ArrayList<>();
        List<Long> fiveScoreList = new ArrayList<>();
        for (EvaluateComplaintVO service : serviceList) {
            serviceNameList.add(service.getServiceName());
            Map<Integer, Long> scoreMap = serviceScoreMap.get(service.getServiceId());
            if (scoreMap == null) {
                scoreMap = new HashMap<>(16);
            }
            Long zeroScore = scoreMap.getOrDefault(0, 0L);
            zeroScoreList.add(zeroScore);
            Long oneScore = scoreMap.getOrDefault(1, 0L);
            oneScoreList.add(oneScore);
            Long twoScore = scoreMap.getOrDefault(2, 0L);
            twoScoreList.add(twoScore);
            Long threeScore = scoreMap.getOrDefault(3, 0L);
            threeScoreList.add(threeScore);
            Long fourScore = scoreMap.getOrDefault(4, 0L);
            fourScoreList.add(fourScore);
            Long fiveScore = scoreMap.getOrDefault(5, 0L);
            fiveScoreList.add(fiveScore);
        }

        Map<String, Object> map = new HashMap<>(16);
        map.put("title", serviceNameList);
        map.put("zeroScore", zeroScoreList);
        map.put("oneScore", oneScoreList);
        map.put("twoScore", twoScoreList);
        map.put("threeScore", threeScoreList);
        map.put("fourScore", fourScoreList);
        map.put("fiveScore", fiveScoreList);
        return map;
    }

    @Override
    public List<EvaluateComplaintVO> listEvaluateServiceByExhibitionId(Long exhibitionManageId, Integer topN) {
        log.info("listEvaluateServiceByExhibitionId - 展会ID查询评价数量前N的服务, exhibitionManageId={}, topN={}", exhibitionManageId, topN);
        QueryWrapper<EvaluateComplaint> queryWrapper = new QueryWrapper<>();
        queryWrapper
                .eq("em.is_deleted", BusinessConstant.DELETE_NO)
                .eq(exhibitionManageId != null, "em.id", exhibitionManageId)
                .isNotNull("si.id")
                .groupBy("si.id")
                .orderByDesc("count(distinct ec.id)")
                .last(topN != null, "limit " + topN)
        ;
        return evaluateComplaintMapper.listEvaluateServiceByExhibitionId(queryWrapper);
    }

    @Override
    public List<EvaluateComplaintVO> countServiceScoreByExhibitionId(Long exhibitionManageId) {
        log.info("countServiceScoreByExhibitionId - 展会ID统计各个服务的星级, exhibitionManageId={}", exhibitionManageId);
        QueryWrapper<EvaluateComplaint> queryWrapper = new QueryWrapper<>();
        queryWrapper
                .eq("ec.is_deleted", BusinessConstant.DELETE_NO)
                .eq(exhibitionManageId != null, "ec.exhibition_manage_id", exhibitionManageId)
                .isNotNull("ec.service_id")
                .groupBy("ec.service_id, ec.score")
        ;
        return evaluateComplaintMapper.countServiceScoreByExhibitionId(queryWrapper);
    }

    @Override
    public Map<String, Object> countHomeServiceEvaluate(Long exhibitionManageId, Long homeId) {
        log.info("countHomeServiceEvaluate - 查询主场服务评价数量, exhibitionManageId={}, homeId={}", exhibitionManageId, homeId);
        QueryWrapper<EvaluateComplaint> queryWrapper = new QueryWrapper<>();
        queryWrapper
                .eq("em.is_deleted", BusinessConstant.DELETE_NO)
                .eq(exhibitionManageId != null, "em.id", exhibitionManageId)
                .eq(homeId != null, "si.service_provider_id", homeId)
                .groupBy("si.id")
                .orderByDesc("count(distinct ec.id)")
        ;
        List<EvaluateComplaintVO> evaluateComplaintList = evaluateComplaintMapper.countHomeServiceEvaluate(queryWrapper);
        if (evaluateComplaintList == null || evaluateComplaintList.isEmpty()) {
            return null;
        }
        Map<String, Object> map = new HashMap<>(16);
        List<String> serviceNames = new ArrayList<>();
        List<Long> evaluateCountList = new ArrayList<>();
        for (EvaluateComplaintVO evaluateComplaintVO : evaluateComplaintList) {
            serviceNames.add(evaluateComplaintVO.getServiceName());
            evaluateCountList.add(evaluateComplaintVO.getEvaluateCount());
        }
        map.put("serviceName", serviceNames);
        map.put("evaluateCount", evaluateCountList);
        return map;
    }

    /**
     * 获取信誉等级数据
     *
     * @param map
     * @param id
     * @return
     */
    private List<String> getEvaluateComplaintList(Map<String, LocalDateTime> map, Long id) {
        List<String> countList = Lists.newArrayList();

        //查询投诉评价记录
        QueryWrapper<EvaluateComplaint> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda()
                .eq(EvaluateComplaint::getIsDeleted, BusinessConstant.DELETE_NO)
                .eq(EvaluateComplaint::getEvaluateServiceProviderId, id)
                .between(Objects.nonNull(map.get("startTime"))
                                && Objects.nonNull(map.get("endTime")),
                        EvaluateComplaint::getCreateTime, map.get("startTime"), map.get("endTime"));
        List<EvaluateComplaint> list = this.list(queryWrapper);

        //查询不良记录数据
        QueryWrapper<ViolationRecord> queryWrapperTwo = new QueryWrapper<>();
        queryWrapperTwo
                .lambda()
                .eq(ViolationRecord::getIsDeleted, BusinessConstant.DELETE_NO)
                .eq(Objects.nonNull(id), ViolationRecord::getSupervisedId, id)
                .between(Objects.nonNull(map.get("startTime"))
                                && Objects.nonNull(map.get("endTime")),
                        ViolationRecord::getCreateTime, map.get("startTime"), map.get("endTime"));
        List<ViolationRecord> violationRecordList = violationRecordService.list(queryWrapperTwo);
        Integer i = 0, i1 = 0, i2 = 0, i3 = 0, i4 = 0, i5 = 0;
        if (Objects.nonNull(list) && list.size() > 0) {
            for (EvaluateComplaint evaluateComplaint : list) {
                if (evaluateComplaint.getScore() == 0) {
                    i++;
                } else if (evaluateComplaint.getScore() == 1) {
                    i1++;
                } else if (evaluateComplaint.getScore() == 2) {
                    i2++;
                } else if (evaluateComplaint.getScore() == 3) {
                    i3++;
                } else if (evaluateComplaint.getScore() == 4) {
                    i4++;
                } else if (evaluateComplaint.getScore() == 5) {
                    i5++;
                }
            }
            countList.add(i1.toString());
            countList.add(i2.toString());
            countList.add(i3.toString());
            countList.add(i4.toString());
            countList.add(i5.toString());
            countList.add(i.toString());
            countList.add(String.valueOf(violationRecordList.size()));
        }
        return countList;
    }

    /**
     * 获取近一周，近一月，近半年，近一年开始跟结束时间
     *
     * @return
     * @throws ParseException
     */
    private Map<String, LocalDateTime> getStartAndEndTime(String make) throws ParseException {
        int sum = 0;
        if ("1".equals(make)) {
            sum = 7;
        } else if ("2".equals(make)) {
            sum = 30;
        } else if ("3".equals(make)) {
            sum = 180;
        } else {
            sum = 365;
        }
        Map<String, LocalDateTime> map = Maps.newHashMap();
        //获取当前日期时间
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String endTime = sdf.format(System.currentTimeMillis());
        Date parse = sdf.parse(endTime);
        LocalDateTime endLocalDateTime = parse.toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime();
        map.put("endTime", endLocalDateTime);
        //获取七天前的日期
        Calendar calendar = Calendar.getInstance();
        calendar.set(Calendar.DATE, calendar.get(Calendar.DATE) - sum);
        String startTime = sdf.format(calendar.getTime());
        Date parse1 = sdf.parse(startTime);
        LocalDateTime startLocalDateTime = parse1.toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime();
        map.put("startTime", startLocalDateTime);
        return map;
    }

    /**
     * id查询评价投诉数量
     *
     * @param evaluateServiceProviderId
     * @return
     */
    @Override
    public int getCountByServiceProviderId(Long evaluateServiceProviderId) {
        log.info("EvaluateComplaintServiceImpl +++++ getCountByServiceProviderId - 通过服务商id查询投诉评价数量 id={}", evaluateServiceProviderId);
        QueryWrapper<EvaluateComplaint> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda()
                .eq(EvaluateComplaint::getIsDeleted, BusinessConstant.DELETE_NO)
                .eq(Objects.nonNull(evaluateServiceProviderId), EvaluateComplaint::getEvaluateServiceProviderId, evaluateServiceProviderId)
                .orderByDesc(EvaluateComplaint::getCreateTime);
        return count(queryWrapper);
    }

}
